package com.ep.demo;

import java.io.InputStream;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class SearchUtils implements ISearchUtils{
	 /**
     * 获取html
     */ 
    public String get(String url) { 
    	// 测试HttpClient用法  
        HttpClient client=new DefaultHttpClient(); 
        HttpGet httpGet=new HttpGet(url);
        String html = "";
        try {
			HttpResponse response = client.execute(httpGet);
			HttpEntity entity = response.getEntity();
			html = EntityUtils.toString(entity);
//			String html = inputToString(entity.getContent());
			new String(html.getBytes(),"UTF-8");
			System.out.println(html);
		}  catch (Exception e) {
			e.printStackTrace();
		}
        return html ; 
    } 
    public String inputToString(InputStream in){
    	  StringBuffer out = new StringBuffer();
    	    try {
				byte[] b = new byte[1024];
				for (int n; (n = in.read(b)) != -1;) {
					out.append(new String(b, 0, n));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		return out.toString();
    }
	public void search(String html, String string) {
        Document doc = Jsoup.parse(html);
        Document document = Jsoup.parseBodyFragment("<div>hahahahhaha</div>");
        Element ele = doc.getElementById("current_price");
//        doc.getElementsByClass("");
//        System.out.println(ele.text());
//        Elements ele=doc.getElementsByTag("div");
//        for(Element e :ele)
//        {
//              System.out.println(e.text());
//        }
	}
	public static void main(String[] args) {
		System.out.println("ceil :-11.5=="+Math.ceil(-11.5));
		System.out.println("8<<3=="+(8<<3));
	}
}
